<cfsilent><!---

CF_Kalendar

COPYRIGHT & LICENSING INFO
-------------------------------------------------------------------

Copyright 2008 TJ Downes - tdownes@sanative.net - http://www.sanative.net

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

--->

<!--- attributes.calendarLinkPage - the page that the user is taken to when they click an event --->
<cfparam name="Attributes.calendarLinkPage" type="string" default="" />
<!--- attributes.ExcludeTimeHeader - boolean to specifiy if the header on the calendar for times is displayed --->
<cfparam name="Attributes.ExcludeTimeHeader" type="boolean" default="no" />
<!--- attributes.KalendarRequest  contains the request based data and rules for Kalendar. --->
<cfparam name="Attributes.KalendarRequest" type="any" />
<!--- attributes.urlAddString - a URL string to add to the calendarLinkPage attribute --->
<cfparam name="Attributes.urlAddString" type="string" default="" />
<!--- attributes.view - defines which display mode to show: day, week, weeklist, month, condensed --->
<cfparam name="Attributes.view" type="string" default="list" />

<!--- Config --->
<!--- TODO: soemthing to make this easier, or be shared across all display views so we dont have the same code in multiple view files --->
<cfscript>
	EventRecords = attributes.KalendarRequest.getReturnedEvents(session.user,request.timezones);
	KalendarConfig = attributes.KalendarRequest.getKalendarConfig();
	FirstDateOfWeek = attributes.KalendarRequest.getFirstDisplayDateOfMonth();
	optionBarVars.view = attributes.view;
	optionBarVars.KalendarRequest = attributes.KalendarRequest;
</cfscript>

</cfsilent>

<cfmodule template="OptionBar.cfm" attributecollection="#optionBarVars#">

<!---- MAIN MONTHLY CALENDAR DISPLAY ---->
<table class="calendarTable">
<!--- set the days of the week across the top of the calendar --->
<!--- TODO: Make more dynamic. This will be important for changing the start day of the week or non-Gregorian calendars --->
<tr id="eventDayRow">
	<cfloop from="1" to="7" index="i">
	<td class="eventDayName"><cfoutput>#left(dayOfWeekAsString(i), 3)#</cfoutput></td>
	</cfloop>
</tr>
<tr id="afterEventDayRow">
	<td colspan="7"></td>
</tr>
<!--- Generate the days of the week --->
<cfloop index="LoopWeek" from="#attributes.KalendarRequest.getFirstWeekOfMonth()#" to="#attributes.KalendarRequest.getLastWeekOfMonth()#">
<tr>
	<cfloop index="LoopIndex" from="0" to="6">
	<cfset thisDay = DateAdd('d', LoopIndex, FirstDateOfWeek) />
	<td class="eventDayHeader"><cfif Month(CreateODBCDate(thisDay)) eq Month(attributes.KalendarRequest.getLinkDate())><cfoutput>#Day(thisDay)#</cfoutput><cfelse>&nbsp;</cfif></td>
	</cfloop>
</tr>
<!--- Output events in the week --->
<tr>
<cfloop index="LoopIndex" from="0" to="6">
	<cfset thisDay = DateAdd('d', LoopIndex, FirstDateOfWeek) />
	<td class="eventDay">
	<cfloop index="i" from="1" to="#ArrayLen(EventRecords)#">
		<cfif Month(CreateODBCDate(thisDay)) eq Month(attributes.KalendarRequest.getLinkDate())>
			<cfoutput>
				<cfif Month(CreateODBCDate(eventRecords[i].StartDate)) eq Month(attributes.KalendarRequest.getLinkDate()) OR Month(CreateODBCDate(eventRecords[i].EndDate)) eq Month(attributes.KalendarRequest.getLinkDate())>
					<cfif DateDiff("d",CreateODBCDate(eventRecords[i].StartDate),CreateODBCDate(DateAdd('d', LoopIndex, FirstDateOfWeek))) GTE 0>
						<cfif CreateODBCDate(eventRecords[i].EndDate) gte CreateODBCDate(DateAdd('d', LoopIndex, FirstDateOfWeek))>
						<div class="eventdiv">
						<!--- this element displays the time and date --->
						<div class="timeHeader<cfif DateFormat(eventRecords[i].StartDate) neq DateFormat(eventRecords[i].EndDate)> spandays</cfif>">
						<cfif eventRecords[i].IsAllDayEvent> 
							all day event
						<cfelse>
							<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate>
								<cfif DateAdd('d',0,DateFormat(eventRecords[i].startDate)) eq thisDay>
									#DateFormat(eventRecords[i].StartDate, 'm/d')# #TimeFormat(eventRecords[i].StartDate, 'h:mm tt')#
								</cfif>
							<cfelse> 
								#TimeFormat(eventRecords[i].StartDate, 'h:mm tt')#
							</cfif>
							<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate>
								<cfif DateAdd('d',0,DateFormat(eventRecords[i].startDate)) neq thisDay>
									End #DateFormat(eventRecords[i].EndDate, "m/d")#
									<cfif TimeFormat(eventRecords[i].EndDate) NEQ  "12:00 AM"> 
										#TimeFormat(eventRecords[i].EndDate, 'h:mm tt')#
									</cfif>
								</cfif>
							</cfif>
						</cfif>
						</div>
						<!--- set the description --->
						<div class="eventDisplay"<cfif len(trim(eventRecords[i].Teaser)) OR len(trim(eventRecords[i].Description))> title="#Attributes.ToolTipFormatter.eventTitleTip(eventRecords[i].StartDate, eventRecords[i].EndDate, Trim(eventRecords[i].Title), KalendarConfig.getToolTipSubLength())#|#Attributes.ToolTipFormatter.eventBodyTip(eventRecords[i].Teaser, eventRecords[i].Description, KalendarConfig.getMaxDescriptionSize())#"</cfif><cfif KalendarConfig.getUseCategoryColors() AND Len(Trim(eventRecords[i].CategoryBGColor))> style="background-color: ###eventRecords[i].CategoryBGColor#;"</cfif>>
							<a title="#Trim(eventRecords[i].Title)#" href="#attributes.calendarLinkPage#?#eventRecords[i].EventIDLabel#=#eventRecords[i].EventID#&amp;View=#attributes.View#&amp;linkDate=#UrlEncodedFormat(attributes.KalendarRequest.getLinkDate())#<cfif len(attributes.urlAddString)>#attributes.urlAddString#</cfif>&KeepThis=true&TB_iframe=true&height=395&width=425" class="thickbox"<cfif KalendarConfig.getUseCategoryColors() AND Len(Trim(eventRecords[i].CategoryTextColor))> style="color: ###eventRecords[i].CategoryTextColor#;"</cfif>>#Trim(eventRecords[i].Title)#</a>
						</div>
						<!--- begin: microformat. Leave hidden --->
						<!--- TODO: verify these are accurate and foolproof --->
						<div style="display:none;" class="vevent">
							<span class="dtstamp">#DateFormat(Now(), "yyyy-mm-dd")#T#TimeFormat(Now(), "HH:mm:ss")#</span>
							<span class="summary title">#Trim(eventRecords[i].Title)#</span>
							<a href="http://#cgi.server_name#/#attributes.calendarLinkPage#?#eventRecords[i].EventIDLabel#=#eventRecords[i].EventID#&amp;View=#attributes.View#&amp;linkDate=#UrlEncodedFormat(attributes.KalendarRequest.getLinkDate())#<cfif len(attributes.urlAddString)>#attributes.urlAddString#</cfif>" class="url">Event Link</a>
							<div class="description">#eventRecords[i].Description#</div>
							<span class="dtstart" title="#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#T#TimeFormat(eventRecords[i].StartDate, "HH:mm:ss")#">#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#T#TimeFormat(eventRecords[i].StartDate, "HH:mm:ss")#</span>
							<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate><span class="dtend" title="<cfif eventRecords[i].EndDate neq eventRecords[i].StartDate>#DateFormat(eventRecords[i].EndDate, "yyyy-mm-dd")#<cfelse>#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#</cfif>T#TimeFormat(eventRecords[i].EndDate, "HH:mm:ss")#"><cfif eventRecords[i].EndDate neq eventRecords[i].StartDate>#DateFormat(eventRecords[i].EndDate, "yyyy-mm-dd")#<cfelse>#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#</cfif>T#TimeFormat(eventRecords[i].EndDate, "HH:mm:ss")#</span></cfif>
						</div>
						<!--- end: microformat --->
						</cfif>
					</cfif>
				</cfif>
			</div>
			</cfoutput>
		<cfelse>
			&nbsp;
		</cfif>
	</cfloop></td>
</cfloop>
</tr>
<cfset FirstDateOfWeek = CreateODBCDate(DateAdd('d', 7, FirstDateOfWeek)) />
</cfloop>
</table>